﻿using System;
using System.Data;
using System.Web.UI;
using BLL;
namespace UI.ModAccount
{
    public partial class ModAccount_AccountDetail : System.Web.UI.Page
    {
        AccountBiz accountBiz = new AccountBiz();
        string account = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            //从URL里面获得ID
            if (Request.QueryString["Account"] != null)
            {
                account = Request.QueryString["Account"].ToString();
            }
            else
            {
                if (Session["user"] != null)
                {
                    User user = Session["user"] as User;
                    account = user.Account.ToString();
                }
                else
                {
                    Response.Write(@"<script language='javascript'>alert('参数不能为空！');</script>");
                    return;
                }
            }
            if (!Page.IsPostBack)
            {

                if (account != "")
                {
                    ShowAccountDetail(account);
                }
            }
        }

        //显示帐号详细信息
        protected void ShowAccountDetail(string account)
        {
            try
            {
                //string strShowSQL = "SELECT * FROM JimView_Account WHERE  AccountID=" + AccountID;
                //SqlDataReader dr = this.link.ExecuteSqlGetDataReader(strShowSQL);
                DataTable dt = accountBiz.GetOneInfo(account);
                if (dt.Rows.Count == 1)
                {
                    lbAccount.Text = dt.Rows[0]["Account"].ToString();
                    lbEmail.Text = dt.Rows[0]["OfficeEmail"].ToString();
                    lbInputTime.Text = dt.Rows[0]["Inputtime"].ToString();
                    lbprofile.Text = dt.Rows[0]["Memo"].ToString();
                    lbSales.Text = dt.Rows[0]["EmpName"].ToString();
                    lbTel.Text = dt.Rows[0]["OfficeTel"].ToString();

                }

            }
            catch (Exception ee)
            {
                throw new Exception(ee.Message);
            }

        }
        protected void lbtnModify_Click(object sender, EventArgs e)
        {
            Response.Redirect("AccountMod.aspx?Account=" + account);
        }

        //把次帐号的所有客户提交给公司或分公司
        protected void lbtnIsPublic_Click(object sender, EventArgs e)
        {
            //Ｎ自己的，Ｙ上交给公司 只有管理员对充公的客户进行再分配
            //状态，N表示关，Y表示活动状态（默认）,Z 表示充公 管理员可以将此客户分配给其他业务员
            //this.link.ExecuteSql("Update Cust_Customer SET State='Z' WHERE AccountID=" + Int32.Parse(strAccountID));
            //Response.Write(@"<script language='javascript'>alert('所有客户充公操作完成！');</script>");
            // lbShowMsg.Text = "所有客户充公操作完成！";
            //Response.Write(@"<a href='Javascript:window.close();'>  [关闭窗口]</a>");
        }

        protected void lbtnInitPassword_Click(object sender, EventArgs e)
        {

            accountBiz.ExecSQL("Update Sys_Account SET Password='5fa285e1bebe0a6623e33afc04a1fbd5' WHERE Account='" + account + "'");
            lbShowMsg.Text = "初始化密码操作完成！Password: 123";
            Response.Write(@"<a href='Javascript:window.close();'>  [关闭窗口]</a>");
        }

        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            accountBiz.ExecSQL("delete from Sys_AccountMenu WHERE Account='" + account + "' ;delete from  Sys_Account  WHERE Account='" + account + "'");
            lbShowMsg.Text = "删除成功: " + account;
            Response.Write(@"<a href='Javascript:window.close();'>  [关闭窗口]</a>");
        }

        protected void lbtnClear_Click(object sender, EventArgs e)
        {
            accountBiz.ExecSQL("delete from Sys_AccountMenu WHERE Account='" + account + "'");
            lbShowMsg.Text = "清除菜单成功: " + account;
            Response.Write(@"<a href='Javascript:window.close();'>  [关闭窗口]</a>");
        }
    }
}
